<template>
	<div>
		<el-form ref="form" :model="form" label-width="120px">
			<el-form-item label="科室名称:">
				<el-input v-model="form.room" style="width:300px ;" placeholder="请输入科室名称"></el-input>
				<el-button type="primary" style="margin-left: 50px;" @click="getdoctor">查询</el-button>
				<el-button type="primary" style="margin-left: 50px;" @click="dialogFormVisible=true">新增排班规则</el-button>
			</el-form-item>	
		</el-form>
		<el-table :data="tableData" style="width: 100%" max-height="500">
			<el-table-column prop="id" label="医生ID" width="250">
			</el-table-column>
			<el-table-column prop="name" label="姓名" width="250">
			</el-table-column>
			<el-table-column prop="title" label="级别" width="250">
			</el-table-column>
			<el-table-column prop="room" label="科室" width="250">
			</el-table-column>
			<el-table-column fixed="right" label="操作">
				<template slot-scope="scope">
					<el-button @click="getschedule(scope.$index, tableData)" type="text" size="small">
						查询
					</el-button>
				</template>
			</el-table-column>
		</el-table>
		<h1>&emsp;</h1>
		<h1>&emsp;</h1>
		<h1>医生排班信息</h1>
		<el-table :data="tableData1" style="width: 100%" max-height="500">
			<el-table-column prop="id" label="医生ID" width="100">
			</el-table-column>
			<el-table-column prop="name" label="姓名" width="100">
			</el-table-column>
			<el-table-column prop="monmn" label="星期一上午" width="100">
			</el-table-column>
			<el-table-column prop="monan" label="星期一下午" width="100">
			</el-table-column>
			<el-table-column prop="tuemn" label="星期二上午" width="100">
			</el-table-column>
			<el-table-column prop="tuean" label="星期二下午" width="100">
			</el-table-column>
			<el-table-column prop="wedmn" label="星期三上午" width="100">
			</el-table-column>
			<el-table-column prop="wedan" label="星期三下午" width="100">
			</el-table-column>
			<el-table-column prop="thurmn" label="星期四上午" width="100">
			</el-table-column>
			<el-table-column prop="thuran" label="星期四下午" width="100">
			</el-table-column>
			<el-table-column prop="frimn" label="星期五上午" width="100">
			</el-table-column>
			<el-table-column prop="frian" label="星期五下午" width="100">
			</el-table-column>
			<el-table-column prop="satmn" label="星期六上午" width="100">
			</el-table-column>
			<el-table-column prop="satan" label="星期六下午" width="100">
			</el-table-column>
			<el-table-column prop="sunmn" label="星期日上午" width="100">
			</el-table-column>
			<el-table-column prop="sunan" label="星期日下午" width="100">
			</el-table-column>
			<el-table-column fixed="right" label="操作">
				<template slot-scope="scope">
					<el-button type="text" size="small" @click="deleteRow(scope.$index,tableData1)">
						删除
					</el-button>
				</template>
			</el-table-column>
		</el-table>

		<el-dialog title="新增排班规则" :visible.sync="dialogFormVisible">
			<el-form ref="form" :model="form1" label-width="80px">
				<el-form-item label="医生编号:">
					<el-input v-model="form1.id" style="width:180px ;"></el-input>
				</el-form-item>
				<el-form-item label="医生姓名:">
					<el-input v-model="form1.name" style="width:180px ;"></el-input>
				</el-form-item>
				<el-form-item label="星期一:" prop="mon">
					<el-select v-model="form1.monmn" placeholder="上午" style="width:150px; ">
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
					<el-select v-model="form1.monan"  placeholder="下午" style="width:150px;margin-left: 50px;" >
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="星期二:" prop="tue">
					<el-select v-model="form1.tuemn" placeholder="上午" style="width:150px; ">
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
					<el-select v-model="form1.tuean"  placeholder="下午" style="width:150px;margin-left: 50px;" >
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="星期三:" prop="wed">
					<el-select v-model="form1.wedmn" placeholder="上午" style="width:150px; ">
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
					<el-select v-model="form1.wedan"  placeholder="下午" style="width:150px;margin-left: 50px;" >
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="星期四:" prop="thur">
					<el-select v-model="form1.thurmn" placeholder="上午" style="width:150px; ">
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
					<el-select v-model="form1.thuran"  placeholder="下午" style="width:150px;margin-left: 50px;" >
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="星期五:" prop="fri">
					<el-select v-model="form1.frimn" placeholder="上午" style="width:150px; ">
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
					<el-select v-model="form1.frian"  placeholder="下午" style="width:150px;margin-left: 50px;" >
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="星期六:" prop="sat">
					<el-select v-model="form1.satmn" placeholder="上午" style="width:150px; ">
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
					<el-select v-model="form1.satan"  placeholder="下午" style="width:150px;margin-left: 50px;" >
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="星期日:" prop="sun">
					<el-select v-model="form1.sunmn" placeholder="上午" style="width:150px; ">
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
					<el-select v-model="form1.sunan"  placeholder="下午" style="width:150px;margin-left: 50px;" >
						<el-option label="在诊" value="在诊"></el-option>
						<el-option label="休息" value="休息"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" style="margin-left: 50px;" @click="submitForm">保存</el-button>
					<el-button type="primary" style="margin-left: 50px;"@click="dialogFormVisible = false">确定</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
	</div>
</template>

<script>
	import {showMsgTitle} from '@/utils/api'
	import {showMsgConfirm} from '@/utils/api'
	import {getRequest}   from '@/utils/api'
	import {postRequest}   from '@/utils/api'
	import {uploadFileRequest}   from '@/utils/api'
	import {putRequest}   from '@/utils/api'
	import {deleteRequest}   from '@/utils/api'
	import {showConstants}   from '@/utils/api'
	export default {
		data() {
			return {
				dialogTableVisible: false,
				dialogFormVisible: false,
				form: {
					room: '',
					value1: ''
				},
				form1: {
					id:'',
					monmn:'',
					monan:'',
					tuemn:'',
					tuean:'',
					wedmn:'',
					wedan:'',
					thurmn:'',
					thuran:'',
					frimn:'',
					frian:'',
					satmn:'',
					satan:'',
					sunmn:'',
					sunan:''
				},
				tableData: [],
				tableData1: [],
				multipleSelection: []
			}
		},
		methods: {
			onSubmit() {
				console.log('submit!');
			},
			submitForm(formName) {
				postRequest('/addschedule',this.form1).then(resp => {
				      
					  
						  alert("已为该医生排班成功！");
					 }).catch((err)=>
					 {
						  alert("该医生排班失败，请重新操作！");
					 }
					 );
			},
			deleteRow(index, rows) {
				console.log(this.tableData1[index].id);
				postRequest('/deleteschedule?id='+this.tableData1[index].id);
				 rows.splice(index, 1);
			},
			getdoctor() {
				this.$axios.get('http://localhost:8081/querydoctor?room=' + this.form.room).then((result) => {
					console.log(result.data);
					this.tableData = result.data
				}).catch((err) => {
					console.log(error);
				});
			},
			getschedule(index, rows) {
				//postRequest('/query/schedule?id='+this.tableData[index].id);
				this.$axios.get('http://localhost:8081/queryschedule?id=' + this.tableData[index].id).then((result) => {
					console.log(result.data);
					this.tableData1 = result.data
				}).catch((err) => {
					console.log(error);
				});
			}
		}
	}
</script>

<style>
</style>
